class Solution
{
public:
    vector<string> alertNames(vector<string> &keyName, vector<string> &keyTime)
    {
        unordered_map<string, vector<int>> keyNameTimes;
        auto timeToInt = [](string &time) -> int
        {
            return 60 * stoi(time.substr(0, 2)) + stoi(time.substr(3, 2));
        };
        int n = keyName.size();
        for (int i = 0; i < n; ++i)
        {
            keyNameTimes[keyName[i]].push_back(timeToInt(keyTime[i]));
        }
        vector<string> result;
        for (auto &[name, times] : keyNameTimes)
        {
            sort(times.begin(), times.end());
            for (int i = 0; i < times.size() - 2; ++i)
            {
                if (times[i + 2] - times[i] <= 60)
                {
                    result.push_back(name);
                    break;
                }
            }
        }
        sort(result.begin(), result.end());
        return result;
    }
};